//
//  RecordViewController.m
//  DeepBreathing
//
//  Created by rimi on 15/12/14.
//  Copyright © 2015年 rimi. All rights reserved.
//

#import "RecordViewController.h"

#import "LoginViewController.h"

#import "ASD.h"

#import "UserModel.h"
#import "HeaderView.h"

#import "ControllerManager.h"
#import "QuestionnaireManger.h"


#import "ViewController.h"



@interface RecordViewController ()




-(void)initializeAppearance;




@end

@implementation RecordViewController

-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    if ([UserModel defaultUser].isLording == NO) {
       LoginViewController *lvv = [[LoginViewController alloc]init];
    
    UINavigationController *navc = [[UINavigationController alloc]initWithRootViewController:lvv];
    
    [self presentViewController:navc animated:NO completion:^{
        
        self.view.alpha = 1;
        
    }];
    }
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    if ([UserModel defaultUser].isLording == NO) {
        self.view.alpha = 0;
    }
    
   _controllerViewArray = @[@"首页完全控制文字",@"首页未控制文字",@"首页部分控制文字"];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initializeAppearance];
    for (int i = 0; i < 2; i ++) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(110 + 110 * i, 250, 2, 45)];
        
        view.backgroundColor = [UIColor whiteColor];
        
        [self.view addSubview:view];
    }
    
    HeaderView *HDV = [[HeaderView alloc]initWithTitleString:nil leftImage:@"个人中心按钮" rightImage:@"历史记录按钮" color:[UIColor clearColor]];
    
    [self.view addSubview:HDV];
    
    HDV.LeftDWblock = ^(){
        
        if ([ControllerManager sharedManager].drawerVC.leftOpen == NO) {
            [[ControllerManager sharedManager].drawerVC openLeftDrawer];
        }
    else if([ControllerManager sharedManager].drawerVC.leftOpen == YES ){
        [[ControllerManager sharedManager].drawerVC closeLeftDrawer];
    }
    };
    
        
        
    HDV.RightDWblock = ^(){
        
    
    };
    
    
     
}
//



-(void)initializeAppearance{
   
    [self.view addSubview:[QuestionnaireManger shareManger].questionnaireView];
    //所有的应该参与翻转动画的视图加到上面
    [[QuestionnaireManger shareManger].questionnaireView addSubview:self.recordButton];
    [[QuestionnaireManger shareManger].questionnaireView addSubview:self.controllerView];
    [[QuestionnaireManger shareManger].questionnaireView addSubview:self.currentMedcineButton];
    [[QuestionnaireManger shareManger].questionnaireView addSubview:self.ACTButton];
      [[QuestionnaireManger shareManger].questionnaireView addSubview:self.remindButton];
    [[QuestionnaireManger shareManger].questionnaireView addSubview:self.iconImageView];
    
    
}

#pragma mark -callback


- (void)onTap {
    [[QuestionnaireManger shareManger] retractAnimationWithOperation:^{
        self.recordButton.hidden = NO;
        self.controllerView.hidden = NO;
        self.currentMedcineButton.hidden = NO;
        self.ACTButton.hidden = NO;
        self.remindButton.hidden = NO;
        self.iconImageView.hidden = NO;

    }];
}

- (void)onRecordButton {
    [[QuestionnaireManger shareManger] launchAnimationWithOpration:^{
        self.recordButton.hidden = YES;
        self.controllerView.hidden = YES;
        self.currentMedcineButton.hidden = YES;
        self.ACTButton.hidden = YES;
        self.remindButton.hidden = YES;
        self.iconImageView.hidden = YES;
    }];
}

#pragma mark - getter



-(UIImageView *)iconImageView{
    
    
    
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 455, 357, 141)];
        _iconImageView.image = [UIImage imageNamed:@"图表"];
        
    }
    return _iconImageView;
}







- (UIButton *)recordButton {
    if (!_recordButton) {
        _recordButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _recordButton.frame = CGRectMake(135, 330, 100, 100);
        [_recordButton setImage:[UIImage imageNamed:@"我有哮喘按钮"] forState:UIControlStateNormal];
        [_recordButton setImage:[UIImage imageNamed:@"我有哮喘按钮2"] forState:UIControlStateHighlighted];
        [_recordButton addTarget:self action:@selector(onRecordButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _recordButton;
}
-(NSArray *)controllerViewArray{
    
    
    if (!_controllerViewArray) {
        
        _controllerViewArray = [NSArray array];
        
       
    }
    return _controllerViewArray;
}
    
-(UIImageView *)controllerView{
    
    
    if (!_controllerView) {
        _controllerView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 450)];
        
        _controllerView.image = [UIImage imageNamed:_controllerViewArray[0]];
        
        
    }
    return _controllerView;
}
    
-(UIButton *)currentMedcineButton{
    
    if (!_currentMedcineButton) {
        _currentMedcineButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(10, 250, 90, 50);
            [button setImage:[UIImage imageNamed:@"当前-用药"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(toMedicine:) forControlEvents:UIControlEventTouchUpInside];
          
            button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 40);
             [button setTitle:@"2" forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:30];
            button;
        });
            }
    return _currentMedcineButton;
}
-(UIButton *)ACTButton{
    
    
    if (!_ACTButton) {
        _ACTButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(120, 250, 90, 50);
           
            
            
            UIGraphicsBeginImageContext(CGSizeMake(90, 50));
            [[UIImage imageNamed:@"其他-评估"] drawInRect:CGRectMake(0, 0, 40, 40) ];
            [[UIImage imageNamed:@"其他评估"] drawInRect:CGRectMake(50, 0, 40, 40)];
            UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
            
            
            UIGraphicsEndImageContext();
            button.highlighted = NO;
          
            [button setImage:image forState:UIControlStateNormal];
            [button setImage:image forState:UIControlStateHighlighted];
            [button addTarget:self action:@selector(toText:) forControlEvents:UIControlEventTouchUpInside];

            button;

             });
    }
    return _ACTButton;
}

-(UIButton *)remindButton{
    
    if (!_remindButton) {
        _remindButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(250, 250, 90, 50);
            [button setImage:[UIImage imageNamed:@"就诊-提醒"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(toRemind:) forControlEvents:UIControlEventTouchUpInside];
            
            button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 40);
            [button setTitle:@"0" forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:30];
            button;
        });
    }
    return _remindButton;
}


-(void)toMedicine:(UIButton *)sender{
    
    NSLog(@"das");
    
}
-(void)toText:(UIButton *)sender{
    NSLog(@"dasd");
}
-(void)toRemind:(UIButton *)sender{
    NSLog(@"dasd");
}
@end
